
import 'package:hongsheng/api/SPClassApiManager.dart';
import 'package:hongsheng/api/SPClassHttpCallBack.dart';
import 'package:hongsheng/app/SPClassApplicaion.dart';
import 'package:hongsheng/model/SPClassMyPointsLogEntity.dart';
import 'package:hongsheng/pages/user/signIn/SPClassSignInPage.dart';
import 'package:hongsheng/utils/SPClassCommonMethods.dart';
import 'package:hongsheng/utils/SPClassImageUtil.dart';
import 'package:hongsheng/utils/SPClassNavigatorUtils.dart';
import 'package:hongsheng/utils/colors.dart';
import 'package:hongsheng/widgets/SPClassBallFooter.dart';
import 'package:hongsheng/widgets/SPClassToolBar.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';


///积分详情
class SPClassIntegralDetail extends StatefulWidget {
  const SPClassIntegralDetail({Key ?key}) : super(key: key);

  @override
  _SPClassIntegralDetailState createState() => _SPClassIntegralDetailState();
}

class _SPClassIntegralDetailState extends State<SPClassIntegralDetail> {
  EasyRefreshController _controller =new EasyRefreshController();
  List<SPClassMyPointsLogList> spProList =[];
  int page =1;
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    SPClassApiManager.spFunGetInstance().spFunPointsMyPointsLog<SPClassMyPointsLogEntity>(params:{"page":'1'},spProCallBack:SPClassHttpCallBack(
        spProOnSuccess: (result){
          spProList =result.spProList;
          setState(() {

          });
        }
    ));
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: SPClassToolBar(
        context,title: "积分明细",
        actions: <Widget>[
          GestureDetector(
            behavior: HitTestBehavior.translucent,
            onTap: (){
              showDialog(context: context,builder: (context){
                return GestureDetector(
                  onTap: (){
                    Navigator.pop(context);
                  },
                  child: Material(
                    color: Colors.transparent,
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: <Widget>[
                        Container(
                          decoration: BoxDecoration(
                            color:Colors.white,
                            borderRadius: BorderRadius.circular(8),
                          ),
                          margin: EdgeInsets.symmetric(horizontal: width(58)),
                          padding: EdgeInsets.symmetric(horizontal: width(15),vertical: width(15)),
                          child: Column(
                            children: <Widget>[
                              Row(
                                children: <Widget>[
                                  GestureDetector(
                                    onTap:(){
                                      Navigator.pop(context);
                                    },
                                    child: Image.asset(
                                      SPClassImageUtil.spFunGetImagePath(
                                          "close"),
                                      width: width(15),
                                    ),
                                  ),
                                ],
                                mainAxisAlignment: MainAxisAlignment.end,
                              ),
                              Text('积分说明',style: TextStyle(fontSize: sp(23),fontWeight: FontWeight.bold),),
                              SizedBox(height: width(28),),
                              Row(
                                children: <Widget>[
                                  ClipOval(
                                    child: Container(
                                      width: width(6),
                                      height: width(6),
                                      color: MyColors.main1,
                                    ),
                                  ),
                                  SizedBox(width: width(4),),
                                  Text('积分可以进入商店兑换实物',style: TextStyle(fontSize: sp(13),color: MyColors.grey_66),),
                                ],
                              ),
                              SizedBox(height: width(12),),
                              Row(
                                children: <Widget>[
                                  ClipOval(
                                    child: Container(
                                      width: width(6),
                                      height: width(6),
                                      color: MyColors.main1,
                                    ),
                                  ),
                                  SizedBox(width: width(4),),
                                  Text('积分可以参与幸运大转盘活动',style: TextStyle(fontSize: sp(13),color: MyColors.grey_66),),
                                ],
                              ),
                              SizedBox(height: width(12),),
                              Row(
                                children: <Widget>[
                                  ClipOval(
                                    child: Container(
                                      width: width(6),
                                      height: width(6),
                                      color: MyColors.main1,
                                    ),
                                  ),
                                  SizedBox(width: width(4),),
                                  Text('更多活动敬请期待',style: TextStyle(fontSize: sp(13),color: MyColors.grey_66),),
                                ],
                              ),
                              SizedBox(height: width(20),),
                              GestureDetector(
                                behavior: HitTestBehavior.translucent,
                                onTap: (){
                                  SPClassNavigatorUtils.spFunPopAll(context);
                                  SPClassNavigatorUtils.spFunPushRoute(context, SPClassSignInPage());
                                },
                                child: Container(
                                  width: width(100),
                                  height: width(30),
                                  decoration: BoxDecoration(
                                    border: Border.all(color: MyColors.main1,width: 0.8),
                                    borderRadius: BorderRadius.circular(150),
                                  ),
                                  alignment: Alignment.center,
                                  child: Text('赚取积分',style: TextStyle(fontSize: sp(13),color: MyColors.main1),),
                                ),
                              )

                            ],
                          ),
                        ),
                      ],
                    ),
                  ),
                );
              }, );
            },
            child: Container(
              padding: EdgeInsets.only(top: width(17),right: width(10)),
              child: Text('积分说明',style: TextStyle(fontSize: sp(12),color: MyColors.grey_99),),
            ),
          )
        ],
      ),
      body: EasyRefresh.custom(
        controller: _controller,
        footer: SPClassBallFooter(
          textColor: Color(0xFF8F8F8F),
        ),
        onLoad: onLoad,
        slivers: <Widget>[
          SliverList(
            delegate: SliverChildListDelegate([
              Container(
                width: MediaQuery.of(context).size.width,
                height: width(100),
                decoration: BoxDecoration(
                  image: DecorationImage(
                      fit: BoxFit.fitWidth,
                      image: AssetImage(
                        SPClassImageUtil.spFunGetImagePath("ic_jifen_bg"),
                      )
                  )
                ),
                margin: EdgeInsets.all(width(12)),
                alignment: Alignment.center,
                padding: EdgeInsets.symmetric(horizontal: width(35)),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: <Widget>[
                    Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: <Widget>[
                        Text('${SPClassApplicaion.spProUserInfo!.spProPoints}',style: TextStyle(fontSize: sp(31),fontWeight: FontWeight.bold,color: Colors.white),),
                        Text('我的积分',style: TextStyle(fontSize: sp(12),color: Colors.white),),
                      ],
                    ),
                    GestureDetector(
                      onTap: (){
                        SPClassNavigatorUtils.spFunPopAll(context);
                        SPClassNavigatorUtils.spFunPushRoute(context, SPClassSignInPage());
                      },
                      child: Container(
                        width: width(92),
                        height: width(23),
                        alignment: Alignment.center,
                        decoration: BoxDecoration(
                          color: Colors.white,
                          borderRadius: BorderRadius.circular(150),
                        ),
                        child:Text('赚取更多积分',style: TextStyle(fontSize: sp(12),color: MyColors.main1),),
                      ),
                    )
                  ],
                ),
              ),
              SizedBox(height: width(20),),
              Row(
                children: <Widget>[
                  SizedBox(width: width(12),),
                  Container(
                    width: height(4),
                    height: height(14),
                    decoration: BoxDecoration(
                        color: Color(0xFFDE3C31),
                        borderRadius: BorderRadius.circular(100)
                    ),
                  ),
                  SizedBox(width: 4,),
                  Text("积分详情",style: TextStyle(fontWeight: FontWeight.w600,fontSize: sp(15)),),
                ],
              ),
              SizedBox(height: width(14),),

            ]),
          ),
          SliverList(
            delegate: SliverChildBuilderDelegate(
                  (context, index) {
                return itemWidget(spProList[index]);
              },
              childCount: spProList.length,
            ),
          ),

        ],
      ),
    );
  }

  Widget itemWidget(SPClassMyPointsLogList data){
    return Container(
      height: width(81),
      alignment: Alignment.center,
      margin: EdgeInsets.only(bottom: width(8),left: width(12),right: width(12)),
      padding: EdgeInsets.symmetric(horizontal: width(15)),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(8),
        boxShadow:[
          BoxShadow(
            offset: Offset(0,0),
            color: Color(0xFF000000).withOpacity(0.1),
            blurRadius:width(6,),),
        ],
      ),
      child: Row(
        children: <Widget>[
          Expanded(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                Text('${data.spProChangeType}-${data.spProChangeDesc}',style: TextStyle(fontSize: sp(15),fontWeight: FontWeight.bold),overflow: TextOverflow.ellipsis,),
                Text(data.spProChangeTime??'',style: TextStyle(fontSize: sp(12),color: MyColors.grey_99),),
              ],
            ),
          ),
          Text('${data.spProChangeCoin}积分',style: TextStyle(fontSize: sp(15),fontWeight: FontWeight.bold,color:data.spProChangeCoin!.startsWith('-')?MyColors.main1: MyColors.grey_33),),

        ],
      ),
    );
  }

  Future onLoad() async{
    page++;
    SPClassApiManager.spFunGetInstance().spFunPointsMyPointsLog<SPClassMyPointsLogEntity>(context: context,params:{"page":page.toString()},spProCallBack:SPClassHttpCallBack(
        spProOnSuccess: (result){
          spProList.addAll(result.spProList);
          setState(() {
          });
        }
    ));
  }

  }
